<template>
	<div class="user">
		<header>
			<el-row :gutter="20">
				<el-col :span="12">
					搜索输入框
					<div style="margin-top: 15px;">
						<el-input placeholder="请输入疾病分类" class="input-with-select" v-model="DiseCategoryselectdata.DicaName"
							style="width:240px; margin-right: 10px;"></el-input>
						<el-select v-model="value" placeholder="请选择" style="width: 100px;" @change="xiala($event,value)">
							<el-option v-for="item in options" :key="item.value" :label="item.label"
								:value="item.value" >
							</el-option>
						</el-select>
					</div>
				</el-col>
				<el-col :span="6">
					<div class="grid-content bg-purple">
						<el-button class="el-icon-search" type="primary" @click="getsousuo()">搜索</el-button>
						<el-button type="danger" @click="dialogVisibleadd=true">添加诊断分类</el-button>
					</div>
				</el-col>
			</el-row>
		</header>
    <!-- 表格内容 -->
		<div class="body">
			<el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
				@selection-change="handleSelectionChange" :stripe="true">
				<el-table-column type="selection" width="55" :stripe="true">
				</el-table-column>
				<el-table-column prop="id" label="序号" width="120">
				</el-table-column>
				<el-table-column prop="dicaName" label="分类编码" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="dicaCode" label="分类名称" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="dicaType" label="疾病类型" show-overflow-tooltip>
				</el-table-column>
				<el-table-column prop="delMark" label="删除状态" show-overflow-tooltip>
				</el-table-column>
				<el-table-column  label="功能" show-overflow-tooltip>
					<template slot-scope="scope">
            <el-button  type="primary" @click="xiugai(scope.$index,scope.row)">修改</el-button>
            <el-button type="danger" @click="shanchu(scope.$index,scope.row)">删除</el-button>
          </template>
				</el-table-column>
			</el-table>
      <!-- 分页 -->
			 <div class="block">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:current-page="queryinfo.page" :page-sizes="[10]" :page-size="10"
					layout="total, sizes, prev, pager, next, jumper" :total="total"
          >
				</el-pagination>
			</div>
      <!-- 修改弹出框 -->
      <el-dialog
        title="提示"
        :visible.sync="dialogVisibleupdate"
        width="30%"
        :before-close="handleClose">
        分类编码:<el-input v-model="DiseCategoryupdatedata.dicaCode" placeholder="请输入疾病助记编码" style="margin-bottom: 10px;"></el-input>
        分类名称:<el-input v-model="DiseCategoryupdatedata.dicaName" placeholder="请输入疾病助记编码" style="margin-bottom: 10px;"></el-input>
        显示顺序号:<el-input v-model="DiseCategoryupdatedata.sequenceNo" placeholder="请输入疾病助记编码" style="margin-bottom: 10px;"></el-input>
        疾病类型:<el-input v-model="DiseCategoryupdatedata.dicaType" placeholder="请输入疾病助记编码" style="margin-bottom: 10px;"></el-input>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleupdate = false">取 消</el-button>
          <el-button type="primary" @click="getxiugai()">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 添加对话框 -->
            <el-dialog
              title="提示"
              :visible.sync="dialogVisibleadd"
              width="30%"
              :before-close="handleClose">
              分类编码:<el-input v-model="DiseCategoryadddata.dicaCode" placeholder="请输入疾病助记编码" style="margin-bottom: 10px;"></el-input>
             分类名称:<el-input v-model="DiseCategoryadddata.dicaName" placeholder="请输入疾病名称" style="margin-bottom: 10px;"></el-input>
             显示顺序号:<el-input v-model="DiseCategoryadddata.sequenceNo" placeholder="请输入国际ICD编码" type="number" style="margin-bottom: 10px;"></el-input>
              疾病类型:<el-input v-model="DiseCategoryadddata.dicaType" placeholder="请输入疾病所属分类" type="number" style="margin-bottom: 10px;"></el-input>
              <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisibleadd = false">取 消</el-button>
                <el-button type="primary" @click="getadd()">确 定</el-button>
              </span>
            </el-dialog>
		</div>
	</div>
</template>

<script>
	import disease from '@/api/his/disease'
	export default {
		data() {
			return {
        value:"无",
        //修改弹出框
        dialogVisibleupdate:false,
        centerDialogVisible:false,
        //表格数据
        tableData:[],
        //下拉数据
        options:[
          {
            value:1,
            label:"中医"
          },
          {
            value:2,
            label:"西医",
          },
        ],
        //添加
                dialogVisibleadd:false,
                DiseCategoryadddata:{
                  	dicaCode:'',
                  	dicaName:'',
                  	sequenceNo:0,
                  	dicaType:0,
                },
        //查询对象
        DiseCategoryselectdata:{
          page:1,
          limit:10,
          DicaName:'',
          DicaType:0,
        },

        //修改对象
        DiseCategoryupdatedata:{
          id:0,
          dicaCode:'',
          dicaName:'',
          sequenceNo:'',
          dicaType:0,
          delMark:1,
        },
        //删除对象
          id:0,
        //分页
        queryinfo:{
          page:0,
        },
        total:0,
			};
		},
		methods: {
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
			},
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
        this.DiseCategoryselectdata.page=val
            disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
              console.log(res)
              this.tableData=res.data.data.disecategory
              this.total=res.data.data.total
            })
			},
      //搜索
      getsousuo(){
          disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
            console.log(res)
            console.log(this.DiseCategoryselectdata.DicaName)
            console.log(this.DiseCategoryselectdata.DicaType)
            this.tableData=res.data.data.disecategory
             this.total=res.data.data.total
          })
      },
      //添加
            getadd(){
              this.dialogVisibleadd=false,
              disease.addDiseCategory(this.DiseCategoryadddata).then((res)=>{
                console.log(res)
                if(res.data.data.flag==true){
                  alert("添加成功")
                  disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
                    console.log(res)
                    console.log(this.DiseCategoryselectdata.DicaName)
                    this.tableData=res.data.data.disecategory
                     this.total=res.data.data.total
                  })
                }else{
                  alert("添加失败")
                }
              })
            },
      //修改
      getxiugai(){
        this.dialogVisibleupdate = false
        disease.updateDiseCategory(this.DiseCategoryupdatedata).then((res)=>{
          console.log(res)
          if(res.data.data.flag==true){
            alert("修改成功")
            disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
              console.log(res)
              console.log(this.DiseCategoryselectdata.DicaName)
              this.tableData=res.data.data.disecategory
               this.total=res.data.data.total
            })
          }else{
            alert("修改失败")
          }
        })
      },
      xiugai(index,row){
        this.dialogVisibleupdate=true
          this.DiseCategoryupdatedata.id=row.id
          this.DiseCategoryupdatedata.dicaCode=row.dicaCode
          this.DiseCategoryupdatedata.dicaName=row.dicaName
          this.DiseCategoryupdatedata.sequenceNo=row.sequenceNo
          this.DiseCategoryupdatedata.dicaType=row.dicaType
      },
      //删除
      shanchu(index,row){
          this.id=parseInt(row.id)
          disease.delereDiseCategory(this.id).then((res)=>{
            console.log(res)
            if(res.data.data.flag==true){
              alert("删除成功")
              disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
                console.log(res)
                console.log(this.DiseCategoryselectdata.DicaName)
                this.tableData=res.data.data.disecategory
                 this.total=res.data.data.total
              })
            }else{
              alert("删除失败")
            }
          })
      },

      //添加诊断分类
          tianjiazhenduan(){
            disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
                this.tableData.push(res.data.data.disecategory[0])
            })
          },
      //下拉框
      xiala(e,val){
        this.DiseCategoryselectdata.DicaType=val
        console.log(this.DiseCategoryselectdata.dicaType)
      },
      handleClose(done) {
              this.$confirm('确认关闭？')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
      },
			},
      beforeMount(){
        disease.pageDiseCategoryQuery(this.DiseCategoryselectdata).then((res)=>{
          console.log(res)
          console.log(this.DiseCategoryselectdata.DicaName)
          this.tableData=res.data.data.disecategory
           this.total=res.data.data.total
        })
      }
	}
</script>

<style>
	.body table td {
		margin: 0px;
		padding: 0px;
		border-collapse: collapse;
		width: 100px;
		text-align: center;
	}

	.body table {
		margin-top: 10px;
	}
</style>
